home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
debugnub
/
CirioNubStart.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-06
|
8KB
|
330 lines
/* begincopyright
Copyright (c) 1988 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
endcopyright */
/*
* CirioNubStart.c
*
* Demers, January 11, 1991 8:24:18 am PST
* Udagawa, December 28, 1990 11:32:58 pm PST
*
* This file calls XR_setjmp, so it can't be optimized.
*/
#include "xr/Errno.h"
#include "xr/Threads.h"
#include "xr/ThreadsBackdoor.h"
#include "xr/ThreadsSignalsPrivate.h"
#include "xr/ThreadsMsg.h"
#include "xr/CirioNubProtocol.h"
#include "xr/CirioNubPrivate.h"
#include "xr/CirioNubInstall.h"
#include "xr/CirioNubEnvironment.h"
#include "xr/CirioNubProcs.h"
#define RESCHED_SELF 1
struct CirioNubState cns;
/*
* signal handlers
*/
static int reschedSigs[] = XR_RESCHED_SIGS;
static int memerrSigs[] = XR_MEMERR_SIGS;
static int interruptSigs[] = XR_INTR_SIGS;
static void
CirioNubReschedHandler(sig, code, scp, addr)
int sig;
int code;
struct sigcontext *scp;
char *addr;
{
XR_SlaveCheckOrders();
}
static void
CirioNubInterruptHandler(sig, code, scp, addr)
int sig;
int code;
struct sigcontext *scp;
char *addr;
{
cns.cns_gotSig = TRUE;
}
static void
CirioNubMemerrHandler(sig, code, scp, addr)
int sig;
int code;
struct sigcontext *scp;
char *addr;
{
int mask;
int *p;
if( !cns.cns_memerrJmpBufValid )
XR_Panic("CirioNubMemerrHandler jmp buf invalid");
mask = sigblock(0);
for( p = &(memerrSigs[0]); *p != 0; p++ ) mask &= (~(*p));
sigsetmask(mask);
(void)XR_longjmp(&(cns.cns_memerrJmpBuf), 1);
}
/*
* init proc -- executed on slave IOP
*/
static void
CirioNubInitialize(clientData)
unsigned clientData;
{
struct sigvec vec;
struct sigvec ovec;
int *p;
cns.cns_gotSig = 0;
/* Install resched handler */
vec.sv_handler = CirioNubReschedHandler;
vec.sv_mask = 0;
vec.sv_flags = SV_INTERRUPT;
for( p = reschedSigs; *p != 0; p++ ) {
if( sigvec(*p, &vec, &ovec) != 0 )
XR_Panic("CirioNubInitialize: sigvec failed (resched)");
}
/* Install interrupt handler */
vec.sv_handler = CirioNubInterruptHandler;
vec.sv_mask = 0;
vec.sv_flags = SV_INTERRUPT;
for( p = interruptSigs; *p != 0; p++ ) {
if( sigvec(*p, &vec, &ovec) != 0 )
XR_Panic("CirioNubInitialize: sigvec failed (interupt)");
}
if( XR_setjmp(&(cns.cns_memerrJmpBuf)) != 0 )
XR_Panic("CirioNubInitialize: target of longjmp");
/* Install memerr handler */
vec.sv_handler = CirioNubMemerrHandler;
vec.sv_mask = 0;
vec.sv_flags = SV_INTERRUPT;
for( p = memerrSigs; *p != 0; p++ ) {
if( sigvec(*p, &vec, NIL) != 0 )
XR_Panic("CirioNubInitialize: sigvec failed (memerr)");
}
}
/*
* memory access tester
*/
bool
CirioNubCanAccess(p, nBytes, write)
char *p;
int nBytes;
bool write;
{
int i, x;
if( XR_setjmp(&(cns.cns_memerrJmpBuf)) == 0 ) {
cns.cns_memerrJmpBufValid = TRUE;
if( write ) {
for( i = 0; i < nBytes; i++ ) {
x = *p; *p++ = x;
}
} else {
for( i = 0; i < nBytes; i++ ) {
x = *p++;
}
}
cns.cns_memerrJmpBufValid = FALSE;
return TRUE;
} else {
cns.cns_memerrJmpBufValid = FALSE;
return FALSE;
}
}
/*
* Kick proc
*/
void
CirioNubKickDebuggee()
{
int i;
# if (!RESCHED_SELF)
int my_pid = getpid();
# endif
# ifdef UNDEFINED_pgrp
(void) killpg(XR_sysArea->sa_pgrpVP, reschedSigs[0]);
# else
for( i = 0; i < XR_sysArea->sa_numVP; i++ ) {
int pid = XR_sysArea->sa_vpe[i].vpe_pid;
if( pid != 0 )
(void) kill(pid, reschedSigs[0]);
}
# endif
for( i = 0; i < XR_sysArea->sa_numIOP; i++ ) {
int pid = XR_sysArea->sa_iope[i].iope_pid;
if( pid == 0 ) continue;
# if (!RESCHED_SELF)
if( pid == my_pid ) continue;
# endif
(void) kill(pid, reschedSigs[0]);
}
}
/*
* start proc -- executed in a thread
*/
static int
CirioNubStartUnconditionally()
{
CirioNubHandle h;
int ans;
int port;
char *portEnv;
char *printConsoleMessagesEnv;
extern char *(getenv());
extern int atoi();
h = CirioNubGetDefaultHandle( 128, 6*1024 );
if( h == NIL ) {
XR_ErrorVMsg "CirioNubStart no slave available\n");
return (-99);
}
(void)CirioNubRegisterCProc(h,
CirioNubProcID_Null, CirioNubServeNull);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_WaitSig, CirioNubServeWaitSig);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_SetDBStat, CirioNubServeSetDBStat);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetBytes, CirioNubServeGetBytes);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_PutBytes, CirioNubServePutBytes);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetWords16, CirioNubServeGetWords16);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_PutWords16, CirioNubServePutWords16);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetWords32, CirioNubServeGetWords32);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_PutWords32, CirioNubServePutWords32);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetThreads, CirioNubServeGetThreads);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_PCtoInfo, CirioNubServePCtoInfo);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_KillWorld, CirioNubServeKillWorld);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_IssueThreadCommand,
CirioNubServeIssueThreadCommand);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetDBStat, CirioNubServeGetDBStat);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetFileEntry, CirioNubServeGetFileEntry);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_LookupSymEntryByName,
CirioNubServeLookupSymEntryByName);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_LookupSymEntryByValue,
CirioNubServeLookupSymEntryByValue);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_LookupSymEntryByID,
CirioNubServeLookupSymEntryByID);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_SkipSymEntryByName,
CirioNubServeSkipSymEntryByName);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_SkipSymEntryByValue,
CirioNubServeSkipSymEntryByValue);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetMatchingSymEntryByName,
CirioNubServeGetMatchingSymEntryByName);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetMatchingSymEntryByValue,
CirioNubServeGetMatchingSymEntryByValue);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetMaxThreads,
CirioNubServeGetMaxThreads);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetThreadFromCTRep,
CirioNubServeGetThreadFromCTRep);
(void)CirioNubRegisterCProc(h,
CirioNubProcID_GetInstrSetAndOpSys,
CirioNubServeGetInstrSetAndOpSys);
port = 0;
if( (portEnv = getenv("CirioPort")) != NIL ) {
port = atoi(portEnv);
if( (port < 4096) || (port >= 8192) ) port = 0;
}
if( (printConsoleMessagesEnv = getenv("CirioPrintConsoleMessages"))
!= NIL ) {
cns.cns_printConsoleMessages = 1;
}
XR_NormalVMsg "CirioNubInstall v %d ", CIRIO_NUB_PROCS_VERSION );
ans = CirioNubInstall(h, port, CirioNubInitialize, 0);
XR_NormalVMsg "... returns %d\n", ans);
return ans;
}
static bool XR_cirioNubStarted = FALSE;
int
XR_run_CirioNub()
{
if( ! XR_cirioNubStarted ) {
XR_cirioNubStarted = TRUE;
return CirioNubStartUnconditionally();
}
return (-1);
}
int
CirioNubStart()
{
return XR_run_CirioNub();
}
int
XR_run_DebugNub()
{
return XR_run_CirioNub();
}